import { http } from '@/utils/http'
import type { CartItem } from '@/types/cart'
type Params = {
  skuId: string
  count: number
}
/**
 * 添加到购物车接口
 */
export const postMemberCartApi = (data: Params) => {
  return http({
    method: 'POST',
    url: '/member/cart',
    data,
  })
}

/**
 * 获取购物车列表数据
 */
export const queryCartData = () => {
  return http<CartItem[]>({
    method: 'GET',
    url: '/member/cart',
  })
}

/**
 * 删除购物车
 */
export const delCart = (ids: Array<string>) => {
  return http({
    method: 'DELETE',
    url: '/member/cart',
    data: {
      ids,
    },
  })
}

/**
 * 修改购物车单品
 * @param skuId skuId
 * @param count 数量
 * @param selected 选中状态
 */
export const changeCartApi = (skuId: string, data: { count?: number; selected?: boolean }) => {
  return http({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data,
  })
}

/**
 * 购物车全选与取消全选
 * @param selected 选中状态
 */
export const changeSelAllStatus = (selected: boolean) => {
  return http({
    method: 'PUT',
    url: '/member/cart/selected',
    data: {
      selected,
    },
  })
}
